﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InHD.model;
using InHD.commands;
using System.Windows.Input;
using InHD.Properties;

namespace InHD.viewmodels
{
    class InvoiceTplListViewModel:WorkspaceViewModel
    {

        #region Value Property
        private List<InvoiceTemplate> _invoiceTemplateRowCollection;
        private InvoiceTemplate _rowIndex = null;
        public string commandExcute = string.Empty;
        #endregion

        #region Constructor
        public InvoiceTplListViewModel( List<InvoiceTemplate> listInvoiceTemplate)
        {
            _invoiceTemplateRowCollection = listInvoiceTemplate;
        }
        #endregion

        #region Presentation Property
        public List<InvoiceTemplate> InvoiceTemplateRowCollection
        {
            get
            {
                return _invoiceTemplateRowCollection;
            }
            set
            {
                if (_invoiceTemplateRowCollection != value)
                {
                    _invoiceTemplateRowCollection = value;
                    OnPropertyChanged("InvoiceTemplateRowCollection");
                }
            }
        }

        public bool canView
        {
            get
            {
                return _rowIndex == null ? false : true;
            }
            set
            {
                canView = value;
            }
        }

        public InvoiceTemplate RowIndexItem
        {
            get
            {
                return this._rowIndex;
            }
            set
            {
                if (value != null)
                {
                    this._rowIndex = value;
                    OnPropertyChanged("RowIndexItem");
                }
            }
        }
        #endregion

        #region Command 
        private RelayCommand _viewInvoiceTemplateCommand;
        public ICommand ViewInvoiceTemplateCommand
        {
            get
            {
                if (_viewInvoiceTemplateCommand == null)
                {
                    _viewInvoiceTemplateCommand = new RelayCommand(
                        (param) => this.ViewInvoiceTemplate(), param=>this.canView);
                }
                return _viewInvoiceTemplateCommand;
            }
        }

        private RelayCommand _closeCommand;
        public ICommand CloseCommand
        {
            get
            {
                if (_closeCommand == null)
                {
                    _closeCommand = new RelayCommand(
                        (param) => this.Close());
                }
                return _closeCommand;
            }
        }

        private RelayCommand _addNewInvoiceTemplateCommand;
        public ICommand AddNewInvoiceTemplateCommand
        {
            get
            {
                if (_addNewInvoiceTemplateCommand == null)
                {
                    _addNewInvoiceTemplateCommand = new RelayCommand(
                        (param) => this.AddNewInvoiceTemplate());
                }
                return _addNewInvoiceTemplateCommand;
            }
        }
        #endregion

        #region Command Method
        void ViewInvoiceTemplate()
        {
            commandExcute = "View";
            OnRequestClose();
        }

        void AddNewInvoiceTemplate()
        {
            commandExcute = "Add";
            OnRequestClose();
        }

        void Close()
        {
            commandExcute = "Close";
            OnRequestClose();
        }
        #endregion

        public override string DisplayName
        {
            get
            {
                try
                {
                    return Resources.Title_Invoice;
                }
                catch (Exception ex)
                {
                    return string.Empty;
                }
            }

        }
    }
}
